﻿using Huirui.Cavan.Application.MainBoundedContext.SystemModule;
using Huirui.Cavan.Domain.MainBoundedContext.SearchModule;
using Huirui.Cavan.Domain.MainBoundedContext.SystemModule;
using Huirui.Cavan.Domain.Seedwork;
using Huirui.Cavan.Presentation.Seedwork;
using Huirui.Cavan.Presentation.ViewModel.SystemModule;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.Mvc;

namespace Huirui.Cavan.Presentation.Controller.SystemModule
{
    public class JobController : EntityController<Job, int, JobSearch, IJobViewModel, IJobAppService>, IJobController
    {
        public override string ControllerName
        {
            get { return ControllerConst.ACCOUNT; }
        }

        public override bool UseDenied
        {
            get { return false; }
        }

        public JobController()
        {
            this.Model = ModelFactory.CreateModel<IJobViewModel>();
        }

        [ActionName(ActionConst.ADD)]
        [HttpGet]
        public ActionResult AddJob()
        {
            return PartialView("~/Views/System/v1/partial/addJobPartial.cshtml");
        }

        [ActionName(ActionConst.ADD)]
        [HttpPost]
        public JsonResult AddJob(JobViewModel model)
        {
            BoolResult jsonResult = null;
            BoolGenericResult<Job> result = this.AppService.AddOrUpdate(model.Item);
            result.Messages.Add(result.Object.Id.ToString());
            result.Messages.Add(result.Object.Name.ToString());
            jsonResult = new BoolResult(result.IsSuccess, result.Messages);

            return Json(jsonResult, "application/json");
        }
    }
}
